clc;
clear;

format short

%% example 1 何晓明
function_u = @(x,y) x.*y.*(1-x/2).*(1-y).*exp(x+y);
function_cor = @(x,y) 1;
function_f = @(x,y) -y.*(1-y).*(1-x-(x.^2)/2).*exp(x+y) - x.*(1-x/2).*(-3*y-y.^2).*exp(x+y);
% x = -1
function_gleft = @(x,y) -1.5*y.*(1-y).*exp(-1+y);
% x = 1
function_gright = @(x,y) 0.5*y.*(1-y).*exp(1+y);
% y = -1
function_gbottom = @(x,y) -2*x.*(1-x/2).*exp(x-1);
% y = 1
function_gtop = @(x,y) 0;
% simple
function_g = function_u;

%% example 2

left = -1.0;
right = 1.0;
bottom = -1.0;
top = 1.0;
vector_N = [2];

basis_type = "P2";
N_gauss_int2d = 9;
boundary_type = "Dirichlet";

% plot_basis_function_2d(basis_type);

error_L2 = zeros(size(vector_N,2), 1);

for i = 1:1
    Nx = vector_N(i);
    Ny = Nx;

    U = poisson_2d(left, right, bottom, top, Nx, Ny, basis_type, N_gauss_int2d, function_cor, function_f, function_g, boundary_type);

    error_L2(i,1) = processing_error_2d(left, right, bottom, top, Nx, Ny, basis_type, N_gauss_int2d, function_u, U, "L2");

    fprintf("完成%d/%d次\n", i, size(vector_N,2));
end

processing_convergence_rate_2d(error_L2, vector_N);
